package Sort;

import java.util.Arrays;

/**
 * @author zhangmin
 * @create 2022-04-18 10:28
 */
public class BubbleSort<T extends Comparable<T>> extends Sort<T> {
    @Override
    public void sort(T[] nums) {
        int n=nums.length;
        boolean isSorted=false;
        for (int i = n-1; i >0&&!isSorted; i--) {
            isSorted=true;
            for (int j = 0; j < i; j++) {
                if (less(nums[j+1],nums[j])){
                    isSorted=false;
                    swap(nums,j,j+1);
                }
            }
        }
    }
    public static void main(String[] args) {
        Integer[] nums={3,5,6,4,1,2};
        BubbleSort<Integer> bubbleSort=new BubbleSort<Integer>();
        bubbleSort.sort(nums);
        System.out.println(Arrays.toString(nums));
    }
}
